﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace RTF2XML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            RTFParser parser = new RTFParser("../../Test Files/test.rtf");
            parser.ParseGroups();
            XmlDocument doc = parser.CreateXML();
            doc.Save("C:\\TestXml.xml");

            Dictionary<string, int> dicUnmatchedControls = parser.GetUnmatchedControlCount();
            List<KeyValuePair<string, int>> lstTemp = dicUnmatchedControls.OrderByDescending(c => c.Value).ToList();
            dicUnmatchedControls.Clear();
            foreach (KeyValuePair<string, int> kv in lstTemp)
            {
                dicUnmatchedControls.Add(kv.Key, kv.Value);
            }

            foreach (KeyValuePair<string, int> kvControl in dicUnmatchedControls)
            {
                this.lvUnmatchedControls.Items.Add(new ListViewItem(new string[] { kvControl.Key, kvControl.Value.ToString() }));
            }

            this.lblTotalUnmatched.Text = dicUnmatchedControls.Sum(c => c.Value).ToString();
        }

        #region Interface
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox ab = new AboutBox();
            ab.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
